package com.iot.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

public class JsonUtil {


    /*json 转换自字符串*/
    static ObjectMapper objectMapper = new ObjectMapper();

    public static String changeString(Object object) {

        String data = null;
        try {
            data = objectMapper.writeValueAsString(object);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return data;
    }


    /*字符串 转为对象*/
    public static Object changeObject(String  str, Object O){
        Object o=null;
        try {
            o= objectMapper.readValue(str, O.getClass());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return o;

    }
}
